package com.whmnx.my.ui.viewmodel;


import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.whmnx.base.bean.TameBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.my.BR;
import com.whmnx.my.R;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 *
 * @author goldze
 * @date 2018/7/18
 */

public class ViewPagerItemViewModel2 extends ItemViewModel<TeamModel> {
    public int text;
    public TeamModel mViewModel;



    public ViewPagerItemViewModel2(@NonNull TeamModel viewModel, int text) {
        super(viewModel);
        this.text = text;
        this.mViewModel = viewModel;
         initView();


    }


    private void initView() {
        Map<String, Object> params = new HashMap<>();
        params.put("uId", SPUtils.getInstance().getString(Constants.USERID));
        if (text == 1){
            params.put("type", 0);
        }else {
            params.put("type", 1);
        }

        params.put("pageIndex", 1);
        params.put("pageSize", 20);
        HttpClient.post(mViewModel.mFragment.getActivity(), Constants.USERTOCHILD, params,new CallBack<List<TameBean>>() {
            @Override
            public void onSuccess(List<TameBean> result) {
                observableList.clear();
                for (TameBean tameBean : result) {
                    observableList.add(new TeamItemViewModel(viewModel,tameBean));
                }
            }
        });
    }

    //给RecyclerView添加ObservableList
    public ObservableList<TeamItemViewModel> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding
    public ItemBinding<TeamItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.grid_team);

}
